package com.qf.md.type.controller;

import com.qf.common.R;
import com.qf.entity.md.type.MdItemType;
import com.qf.md.type.service.MdItemTypeService;
import com.qf.md.type.vo.MdItemTypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/28
 */
@RestController
@RequestMapping("/md/type")
public class MdItemTypeController {
    @Resource
    private MdItemTypeService mdItemTypeService;

    @GetMapping("/list")
    public R<List<MdItemTypeVO>> queryList(){
        return R.ok(mdItemTypeService.queryAllMdItemType());
    }
    @GetMapping("/like")
    public R<List<MdItemTypeVO>> likeTypeNameOrEnableFlag(String itemTypeName,String enableFlag){
        System.out.println(itemTypeName+"<--------->"+enableFlag);
        List<MdItemTypeVO> mdItemTypeVOS = mdItemTypeService.queryByItemNameOrEnableFlag(itemTypeName, enableFlag);
        return R.ok(mdItemTypeVOS);
    }
    @PostMapping("/del")
    public R<Long> del(Long itemTypeId){
        System.out.println("itemTypeId删除:"+itemTypeId);
        return R.ok(mdItemTypeService.delByItemTypeId(itemTypeId));
    }

    @GetMapping("/info")
    public R<MdItemType> info(Long itemTypeId){
        return R.ok(mdItemTypeService.queryByItemTypeId(itemTypeId));
    }

    @PostMapping("/add")
    public R<Long> addType(@RequestBody MdItemType mdItemType){
        System.out.println("新增："+mdItemType);
        return R.ok(mdItemTypeService.addMdType(mdItemType));
    }

    @PostMapping("/update")
    public R<Long> updateType(@RequestBody MdItemType mdItemType){
        System.out.println("修改："+mdItemType);
        return R.ok(mdItemTypeService.updateType(mdItemType));
    }
}
